This page collects R code and materials from my Computational Social Science course at Rutgers University. The course combines theoretical discussion with hands-on training in R. It is a doctoral seminar that offers a gentle introduction to computational methods, both for people with some coding experience and for those just starting to learn. Topics include an introduction to R, survey data analysis, APIs, web scraping, network analysis, data visualization, text analysis, large language models, machine learning, and research ethics.
R code for the 2026 lectures
- Introduction to R Data types and structures, flow control, packages, reading and writing files
- Analyzing survey data Descriptives, recoding, regression, survey weights
- Working with APIs Collecting Bluesky posts, followers, and threads
- Web scraping rvest, XPath, regular expressions
- Network analysis 1 Network data, descriptives, plots, and layouts
- Network analysis 2 Reciprocity, transitivity, homophily
- Network analysis 3 Exponential random graph models
- Data visualization Introduction to ggplot2
- Text analysis 1 Preprocessing, term frequencies, tf-idf, sentiment
- Text analysis 2 N-grams, topic models, structural topic models
- Large language models 1 Classification, extraction, summarization, structured output, images
- Large language models 2 Personas, prompt design, comparing models, validation
- Machine learning tidymodels, classification, regression
Data
The scripts download most of what they need. You can also get the data files here:
- Survey data Pew Research Center survey with codebook (Week 3)
- Network data Example networks (Weeks 6–7)
- State of the Union speeches Text data (Week 11)
- Images for the LLM examples Photos and memes (Weeks 12–13)
The LLM scripts need your own API keys for OpenAI, Gemini, or the Guardian; the code shows where to set them.
Recommended books
- Salganik, M. J. (2017). Bit by bit: Social research in the digital age. Read online.
- Wickham, H., Çetinkaya-Rundel, M., & Grolemund, G. (2023). R for data science (2nd ed.). Read online.
- Long, J. D., & Teetor, P. (2019). R cookbook (2nd ed.). Read online.
- Silge, J., & Robinson, D. (2017). Text mining with R. Read online.
The 2023 version
The 2023 version of the course had separate weeks on network groups and communities (QAP, permutation tests) and did not cover large language models. Its materials are still available.
- 2023 syllabus (PDF) 16:194:672, Spring 2023
- Introduction to R Data formats, flow control, packages
- Analyzing survey data Descriptives, recoding, GLM, weights
- Working with APIs Twitter, Reddit, Internet Archive, bibliometrics
- Web scraping rvest, XPath, pattern matching
- Network analysis 1 Network data, network descriptives
- Network analysis 2 Reciprocity, transitivity, homophily
- Network analysis 3 Communities, permutation tests, QAP and netlm
- Network analysis 4 Exponential random graph models
- Data visualization Introduction to ggplot2
- Text analysis 1 Preprocessing, term frequencies, sentiment
- Text analysis 2 N-grams, topic models
- Machine learning tidymodels, classification, regression
